// Decompiled by Jad v1.5.8f. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3)
// Source File Name:   LoginAction.java

package org.fiel.struts.actions;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.Logger;
import org.apache.struts.action.*;
import org.fiel.login.ValidateUser;
import org.fiel.struts.forms.LoginForm;

public class LoginAction extends Action
{
    private static Logger logger = Logger.getLogger(LoginAction.class);
    
    public LoginAction()
    {
    }
    
    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException
    {
        String forwardName = "error";
        try
        {
            LoginForm loginForm = (LoginForm)form;
            org.fiel.login.FielPrincipal principal = null;
            ValidateUser validateUser = new ValidateUser();
            principal = validateUser.checkCredentials(loginForm.getUsername(), loginForm.getPassword());
            if(principal != null)
            {
                request.getSession().setAttribute("userPrincipal", principal);
                forwardName = "inicio";
            }
        }
        catch(Exception exception)
        {
            logger.error("ERROR", exception);

            return mapping.findForward(forwardName);
        }
        
        return mapping.findForward(forwardName);
    }
}
